package com.lee.actorAndThread

/**
 * Created by alex on 15-4-21.
 */

import akka.actor._
import akka.testkit.CallingThreadDispatcher

object ActorAndThread extends App{

  implicit val system = ActorSystem()

  val echoServers = (1 to 10).map(x=>
    system.actorOf( Props( new EchoServer(x.toString))
      .withDispatcher(CallingThreadDispatcher.Id)
    )
  )

  (1 to 100000).foreach(msg =>
    echoServers(scala.util.Random.nextInt(10)) ! msg.toString)

  system.shutdown
}

class EchoServer(name: String) extends Actor {

  override def receive: Receive = {
    case msg => println("server " + name + " echo " +
        msg + " by " + Thread.currentThread().getName
      )
  }
}
